package gearunits.models {
	import sandy.primitive.Primitive3D;
	import sandy.core.scenegraph.Geometry3D;
	import sandy.core.scenegraph.Shape3D;

	public class SMeshBuildingTurret extends Shape3D implements Primitive3D {
		private var l:Geometry3D;

		private function f(v1:Number,v2:Number,v3:Number,uv00:Number,uv01:Number,uv10:Number,uv11:Number,uv20:Number,uv21:Number,normX:Number,normY:Number,normZ:Number):void {
			var uv1:Number = l.getNextUVCoordID();
			var uv2:Number = uv1 + 1;
			var uv3:Number = uv2 + 1;

			l.setUVCoords(uv1,uv00,1-uv01);
			l.setUVCoords(uv2,uv10,1-uv11);
			l.setUVCoords(uv3,uv20,1-uv21);

			l.setFaceVertexIds(l.getNextFaceID(), v1,v2,v3);
			l.setFaceUVCoordsIds(l.getNextFaceUVCoordID(), uv1,uv2,uv3);
			l.setFaceNormal(l.getNextFaceNormalID(), normX,normZ,normY);
		}

		private function f4(v1:Number,v2:Number,v3:Number,v4:Number,uv00:Number,uv01:Number,uv10:Number,uv11:Number,uv20:Number,uv21:Number,uv30:Number,uv31:Number,normX:Number,normY:Number,normZ:Number):void {
			var uv1:Number = l.getNextUVCoordID();
			var uv2:Number = uv1 + 1;
			var uv3:Number = uv2 + 1;
			var uv4:Number = uv3 + 1;

			l.setUVCoords(uv1,uv00,1-uv01);
			l.setUVCoords(uv2,uv10,1-uv11);
			l.setUVCoords(uv3,uv20,1-uv21);
			l.setUVCoords(uv4,uv30,1-uv31);

			l.setFaceVertexIds(l.getNextFaceID(),v1,v2,v3,v4);
			l.setFaceUVCoordsIds(l.getNextFaceUVCoordID(),uv1,uv2,uv3,uv4);
			l.setFaceNormal(l.getNextFaceNormalID(),normX,normZ,normY);
		}

		private function f2(v1:Number,v2:Number,v3:Number):void {
			l.setFaceVertexIds(l.getNextFaceID(), v1,v2,v3);
		}

		private function v(vx:Number,vy:Number,vz:Number):void {
			l.setVertex(l.getNextVertexID(),vx,vz,vy);
		}

		public function SMeshBuildingTurret( p_Name:String=null ) {
			super( p_Name );
			geometry = generate();
		}

		public function generate(... arguments):Geometry3D {
			l = new Geometry3D();
			v(4.000000,4.000000,0.000000);
			v(4.000000,-4.000000,0.000000);
			v(-4.000000,-3.999999,0.000000);
			v(-3.999998,4.000001,0.000000);
			v(3.200002,3.199998,1.600000);
			v(3.199998,-3.200002,1.600000);
			v(-3.200001,-3.199999,1.600000);
			v(-3.200000,3.200000,1.600000);
			v(2.121320,2.121320,2.400000);
			v(3.000000,-0.000000,2.400000);
			v(2.121320,-2.121320,2.400000);
			v(-0.000000,-3.000000,2.400000);
			v(-2.121321,-2.121320,2.400000);
			v(-3.000000,-0.000000,2.400000);
			v(-2.121321,2.121320,2.400000);
			v(-0.000001,3.000000,2.400000);
			v(2.121319,2.121321,3.600000);
			v(3.000000,0.000002,3.600000);
			v(2.121321,-2.121320,3.600000);
			v(-0.000000,-3.000000,3.600000);
			v(-2.121321,-2.121320,3.600000);
			v(-3.000000,0.000002,3.600000);
			v(-2.121319,2.121322,3.600000);
			v(0.000004,3.000000,3.600000);
			v(-0.000000,-0.000000,2.400000);
			v(-0.000000,-0.000000,3.600000);

			f(24,8,9,0.156762,0.610622,0.313524,0.675555,0.221695,0.767384,-0.000000,0.000000,-1.000000);
			f(25,17,16,0.610622,0.609234,0.767384,0.544301,0.767384,0.674167,0.000000,0.000000,1.000000);
			f(24,9,10,0.156762,0.610622,0.221695,0.767384,0.091829,0.767384,0.000000,0.000000,-1.000000);
			f(25,18,17,0.610622,0.609234,0.675555,0.452472,0.767384,0.544301,0.000000,0.000000,1.000000);
			f(24,10,11,0.156762,0.610622,0.091829,0.767384,0.000000,0.675555,0.000000,0.000000,-1.000000);
			f(25,19,18,0.610622,0.609234,0.545689,0.452472,0.675555,0.452472,0.000000,-0.000000,1.000000);
			f(24,11,12,0.156762,0.610622,0.000000,0.675555,0.000000,0.545689,0.000000,0.000000,-1.000000);
			f(25,20,19,0.610622,0.609234,0.453860,0.544301,0.545689,0.452472,0.000000,-0.000000,1.000000);
			f(24,12,13,0.156762,0.610622,0.000000,0.545689,0.091829,0.453860,0.000000,0.000000,-1.000000);
			f(25,21,20,0.610622,0.609234,0.453860,0.674167,0.453860,0.544301,-0.000000,-0.000000,1.000000);
			f(24,13,14,0.156762,0.610622,0.091829,0.453860,0.221695,0.453860,0.000000,-0.000000,-1.000000);
			f(25,22,21,0.610622,0.609234,0.545689,0.765996,0.453860,0.674167,-0.000000,0.000000,1.000000);
			f(24,14,15,0.156762,0.610622,0.221695,0.453860,0.313524,0.545689,0.000000,-0.000000,-1.000000);
			f(25,23,22,0.610622,0.609234,0.675555,0.765996,0.545689,0.765996,-0.000000,0.000000,1.000000);
			f(24,15,8,0.156762,0.610622,0.313524,0.545689,0.313524,0.675555,-0.000000,-0.000000,-1.000000);
			f(25,16,23,0.610622,0.609234,0.767384,0.674167,0.675555,0.765996,0.000000,0.000000,1.000000);
			f(15,23,8,0.863297,0.138741,0.931167,0.138950,0.863015,0.230570,0.382683,0.923880,-0.000002);
			f(23,16,8,0.931167,0.138950,0.930886,0.230778,0.863015,0.230570,0.382684,0.923879,-0.000000);
			f(14,22,15,0.699232,0.896069,0.767102,0.895861,0.699513,0.987898,-0.382684,0.923879,-0.000001);
			f(22,23,15,0.767102,0.895861,0.767384,0.987690,0.699513,0.987898,-0.382682,0.923880,0.000002);
			f(13,21,14,0.698833,0.766204,0.766704,0.765996,0.699232,0.896069,-0.923880,0.382684,-0.000001);
			f(21,22,14,0.766704,0.765996,0.767102,0.895861,0.699232,0.896069,-0.923879,0.382684,0.000001);
			f(12,20,13,0.931847,0.360644,0.999718,0.360435,0.932129,0.452472,-0.923880,-0.382684,-0.000000);
			f(20,21,13,0.999718,0.360435,1.000000,0.452264,0.932129,0.452472,-0.923880,-0.382683,0.000001);
			f(11,19,12,0.931449,0.230778,0.999320,0.230570,0.931847,0.360644,-0.382684,-0.923879,0.000000);
			f(19,20,12,0.999320,0.230570,0.999718,0.360435,0.931847,0.360644,-0.382684,-0.923880,0.000000);
			f(10,18,19,0.931167,0.138950,0.999038,0.138741,0.999320,0.230570,0.382684,-0.923880,0.000000);
			f(10,19,11,0.931167,0.138950,0.999320,0.230570,0.931449,0.230778,0.382683,-0.923880,-0.000000);
			f(9,17,18,0.862616,0.360435,0.930487,0.360643,0.930205,0.452472,0.923880,-0.382683,0.000001);
			f(9,18,10,0.862616,0.360435,0.930205,0.452472,0.862335,0.452264,0.923880,-0.382683,-0.000000);
			f(8,16,17,0.863015,0.230570,0.930886,0.230778,0.930487,0.360643,0.923879,0.382684,0.000000);
			f(8,17,9,0.863015,0.230570,0.930487,0.360643,0.862616,0.360435,0.923880,0.382683,-0.000001);
			f(4,0,3,0.816948,0.045108,0.862335,0.000000,0.860946,0.452472,0.000000,0.894427,0.447214);
			f(4,3,7,0.816948,0.045108,0.860946,0.452472,0.815838,0.407086,0.000000,0.894427,0.447214);
			f(2,6,7,0.768667,0.452472,0.858980,0.511868,0.857954,0.846292,-0.894427,0.000000,0.447213);
			f(2,7,3,0.768667,0.452472,0.857954,0.846292,0.767384,0.870502,-0.894427,0.000000,0.447213);
			f(1,5,2,0.363547,0.453860,0.453860,0.513256,0.362265,0.871890,-0.000000,-0.894428,0.447213);
			f(5,6,2,0.453860,0.513256,0.452834,0.847680,0.362265,0.871890,-0.000000,-0.894427,0.447214);
			f(0,4,1,0.858980,0.452472,0.949549,0.476682,0.860262,0.870502,0.894428,0.000000,0.447213);
			f(4,5,1,0.949549,0.476682,0.950575,0.811106,0.860262,0.870502,0.894427,-0.000000,0.447215);
			f(4,7,6,0.816948,0.045108,0.815838,0.407086,0.453860,0.405976,-0.000000,0.000000,1.000000);
			f(4,6,5,0.816948,0.045108,0.453860,0.405976,0.454971,0.043998,0.000000,-0.000000,1.000000);
			f(0,1,2,0.001388,0.453860,0.000000,0.001388,0.452472,0.000000,0.000000,0.000000,-1.000000);
			f(0,2,3,0.001388,0.453860,0.452472,0.000000,0.453860,0.452472,0.000000,-0.000000,-1.000000);

			this.x = 0.000000;
			this.y = 0.000000;
			this.z = 0.000000;

			this.rotateX = 0.000000;
			this.rotateY = 0.000000;
			this.rotateZ = 0.000000;

			this.scaleX = 1.000000;
			this.scaleY = 1.000000;
			this.scaleZ = 1.000000;
			return (l);
		}
	}
}